

<template>
    <div>
        <!--            标题-->
        <el-row class=" border_bottom" type="flex" justify="start">
            <el-col :span="3">
                <h1> 管理员列表</h1>
            </el-col>
        </el-row>
        <!--表格-->
        <el-row>
            <template>
                <el-table
                        ref="multipleTable"
                        :data="managerList"
                        tooltip-effect="dark"
                        style="width: 100%"
                        @selection-change="handleSelectionChange">
                    <el-table-column
                            prop="adminId"
                            label="ID"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="adminName"
                            label="管理员名称"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="adminCreateTime"
                            label="创建时间"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="adminLastLoginTime"
                            label="最后登录时间"
                            show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column
                            label="操作"
                    >
                        <template slot-scope="scope">
                            <el-button type="text" @click="getLog( scope.row.adminId)">查看日志</el-button>
                            <el-button type="text" v-if="scope.row.adminName=='admin'" @click="updateManagerInfo( scope.row.adminId,scope.row.adminName)" disabled>修改</el-button>
                            <el-button type="text" v-else @click="updateManagerInfo( scope.row.adminId,scope.row.adminName)" >修改</el-button>
                            <el-button type="text"  v-if="scope.row.adminName=='admin'" @click="delManager( scope.row.adminId)" disabled>删除</el-button>
                            <el-button type="text"  v-else @click="delManager( scope.row.adminId)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </template>
        </el-row>

        <el-row>
            <el-button type="primary" plain @click="addManager">新增管理员</el-button>
        </el-row>
    </div>
</template>
<script>
    import router from "@/router";
    import form from "@/components/set/form";
    import ActionType from "@/store/ActionType";
    import  qs from 'qs'
    export default {
        name: "AccountManage",
        data() {
            return {
                currentmanager:'',
                managerList:[],
                multipleSelection: [],
                currentPage: '',
                currentPage2: 5,
                currentPage3: 5,
                currentPage4: 4,
                // 当前查询id
                currentSearchId:'',
            }
        },
        created() {
            this.getAdminList()
        },
        methods: {
            toggleSelection(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                // 分页查询
                //发起请求
                this.$axios.post('/api/getPagingData',{currentPage:val}).then((res)=>{
                    this.managerList=res.data
                    console.log(`当前第 ${val}页数据：`+res.data);
                })
            },

            getAdminList(){
                this.$axios.post('/api/admin/list').then((res)=>{

                    this.managerList=res.data.data
                    console.log(this.managerList)
                })
            },


            updateManagerInfo(adminId,adminName){
                const currentAdmin={
                    adminId,adminName
                }
                sessionStorage.setItem('currentAdmin',JSON.stringify(currentAdmin))
                // sessionStorage.setItem('currentAdmin',JSON.stringify(this.$store.getters.getCurrentAdmin))
                // 设置当前管理员的角色列表

                //获取当前用户所属角色
                this.$axios.post('/api/admin/updateDetail2?adminId='+currentAdmin.adminId).then((res) => {
                    console.log('获取当前用户所属角色');
                    console.log(this.currentRoleArr);
                    this.currentRoleArr= res.data.data.roleId
                    sessionStorage.setItem('currentRoleArr',JSON.stringify(res.data.data.roleId))

                })


                //跳转
                this.$router.push({name:'EditManager'})


            },
            addManager(){
                this.$router.push('/addmanager')
            },
            getLog(adminId){
                const currentAdmin={
                    adminId,
                    adminName:''
                }
                sessionStorage.setItem('setCurrentAdminActions',JSON.stringify(currentAdmin))

                //跳转
                this.$router.push({name:'LogList'})





            },
            // 删除管理员
            delManager(adminIds){
                // this.currentSearchId=id
                this.$confirm('此操作将永久删除该信息, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //发起请求
                    this.$axios.post('/api/admin/delete?adminIds=',[...[adminIds]]).then((res)=>{
                        console.log(res);
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        this.getAdminList()
                    })

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },

        }
    }
</script>

<style scoped>

    .b1 {
        /*border: 1px solid red;*/
    }

    .b2 {
        /*border: 1px solid blue;*/
    }

    .border_bottom {

        border-bottom: 1px solid grey;
    }

    .el-input {
        display: inline-block;
    }

    span {
        margin-top: 20px;
    }

    .middle {
        align-items: center;
    }
</style>